
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!--link th:href="@{/static/zui/css/zui.css}" href="/static/zui/css/zui.css" rel="stylesheet"-->
    <!--link th:href="@{/static/my/my.css}" href="/static/my/my.css" rel="stylesheet"-->

    <link rel="stylesheet" type="text/css" th:href="@{/static/easyui/themes/default/easyui.css}" href="/static/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" th:href="@{/static/easyui/themes/icon.css}" href="/static/easyui/themes/icon.css">
    <!--link rel="stylesheet" type="text/css" href="../demo.css"-->
	
	<script type="text/javascript" th:src="@{/static/easyui/jquery.min.js}" src="/static/easyui/jquery.min.js?v=1"></script>
	<script type="text/javascript" th:src="@{/static/easyui/jquery.easyui.min.js}" src="/static/easyui/jquery.easyui.min.js?v=1"></script>

</head>
<body>
<div class="empty-split"></div>

<div class="easyui-layout" style="width:900px;height:550px;">
	<div data-options="region:'east',split:true,title:'权限管理',collapsible:false" style="width:300px;">
		<a id="btnSave" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save',size:'small'">保存</a>
		<a id="btnOpen" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',size:'small'">展开</a>
		<a id="btnFold" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',size:'small'">折叠</a>
		<div id="tt2"></div>
	</div>
	<div data-options="region:'center',title:''" style="padding:0">

		<table id="dg" title="用户管理" class="easyui-datagrid" style="width:598px;height:450px"
				toolbar="#toolbar" pagination="true"
				pageList="[2,5,10,15,20]" pageSize="2"
				rownumbers="true" fitColumns="true" singleSelect="true">
			<thead>
				<tr>
					<th field="firstname" width="50">First Name</th>
					<th field="lastname" width="50">Last Name</th>
					<th field="phone" width="50">Phone</th>
					<th field="email" width="50">Email</th>
				</tr>
			</thead>
		</table>
		<div id="toolbar">
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">New User</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">Edit User</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">Remove User</a>
		</div>

	</div>
</div>

<div class="empty-split"></div>

<div id="dlg" class="easyui-dialog" style="width:400px" data-options="closed:true,modal:true,border:'thin',buttons:'#dlg-buttons'">
	<form id="fm" method="post" novalidate style="margin:0;padding:20px 50px">
		<h3>User Information</h3>
		<div style="margin-bottom:10px">
			<input name="firstname" class="easyui-textbox" required="true" label="First Name:" style="width:100%">
		</div>
		<div style="margin-bottom:10px">
			<input name="lastname" class="easyui-textbox" required="true" label="Last Name:" style="width:100%">
		</div>
		<div style="margin-bottom:10px">
			<input name="phone" class="easyui-textbox" required="true" label="Phone:" style="width:100%">
		</div>
		<div style="margin-bottom:10px">
			<input name="email" class="easyui-textbox" required="true" validType="email" label="Email:" style="width:100%">
		</div>
	</form>
</div>
<div id="dlg-buttons">
	<a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveUser()" style="width:90px">Save</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a>
</div>

<!-- ZUI Javascript组件 -->
<!--script th:src="@{/static/zui/js/zui.js}" src="/static/zui/js/zui.js"></script-->

<script th:src="@{/static/my/my.js}" src="/static/my/my.js"></script>

<script type="text/javascript">
	$.get("/static/my/tree_data1.json", function(_data){
		console.log("====", _data);
		$('#tt2').tree({
			//url: ...,
			animate: true,
			checkbox: true,
			data: _data
		});
		console.log("====", "xxx");
	});
	$.get("/static/my/get_users.json", function(_data){
		console.log("====", _data);
		//$('#dg').datagrid('loadData', _data);
		$('#dg').datagrid({
			data: _data,
			pageList: [2,5,10,15,20],
			pageSize: 2
		});
	});
	

	// 展开和折叠
	$('#btnOpen').bind('click', function(){
		var rootNode = $('#tt2').tree('getRoot');
		//expandAll
		$('#tt2').tree('expandAll', rootNode.target);
	});
	$('#btnFold').bind('click', function(){
		var rootNode = $('#tt2').tree('getRoot');
		//expandAll
		$('#tt2').tree('collapseAll', rootNode.target);
	});
	
	var url;
	function newUser(){
		$('#dlg').dialog('open').dialog('center').dialog('setTitle','New User');
		$('#fm').form('clear');
		url = 'save_user.php';
	}
	function editUser(){
		var row = $('#dg').datagrid('getSelected');
		if (row){
			$('#dlg').dialog('open').dialog('center').dialog('setTitle','Edit User');
			$('#fm').form('load',row);
			url = 'update_user.php?id='+row.id;
		}
	}
	function saveUser(){
		$('#fm').form('submit',{
			url: url,
			onSubmit: function(){
				return $(this).form('validate');
			},
			success: function(result){
				var result = eval('('+result+')');
				if (result.errorMsg){
					$.messager.show({
						title: 'Error',
						msg: result.errorMsg
					});
				} else {
					$('#dlg').dialog('close');		// close the dialog
					$('#dg').datagrid('reload');	// reload the user data
				}
			}
		});
	}
	function destroyUser(){
		var row = $('#dg').datagrid('getSelected');
		if (row){
			$.messager.confirm('Confirm','Are you sure you want to destroy this user?',function(r){
				if (r){
					$.post('destroy_user.php',{id:row.id},function(result){
						if (result.success){
							$('#dg').datagrid('reload');	// reload the user data
						} else {
							$.messager.show({	// show error message
								title: 'Error',
								msg: result.errorMsg
							});
						}
					},'json');
				}
			});
		}
	}
</script>

</body>
</html>